package com.quanquan.store.service;

import utils.PayUtils;
import utils.StringUtils;
import utils.UUIDGenerator;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName:Test
 * @Description:TODO
 * @Author:xiongjunbao
 * @Date:2019/11/5 13:50
 * @Version 1.0
 */
public class Test {

    public static void main(String[] args) {



        String nonceStr = StringUtils.getRandomStringByLength(32);
        String secert = "liuhehuanleganggouwuzhongxin2018";
        Map<String, String> packageParams = new HashMap<>();
        packageParams.put("appid", "wx34889a7da30650cb");// 商户appid
        packageParams.put("mch_id", "1516722861");// 商户id
        packageParams.put("nonce_str", nonceStr);// 32位随机字符串
        packageParams.put("bill_date", "20191105");// 支付金额，这边需要转成字符串类型，否则后面的签名会失败
        packageParams.put("bill_type", "ALL");// 客户端的ip地址
        String prestr = PayUtils.createLinkString(packageParams);
        System.out.println(prestr);
//        packageParams.put("sign",prestr);// 商品名称
        String mysign = PayUtils.sign(prestr, secert, "utf-8").toUpperCase();
        // 拼接统一下单接口使用的xml数据，要将上一步生成的签名一起拼接进去
        String xml =  "<xml>"
                    + "<appid>" + "wx34889a7da30650cb" + "</appid>"
                    + "<bill_type>" + "ALL" + "</bill_type>"
                    + "<bill_date>" + "20191105" + "</bill_date>"
                    + "<mch_id>" + "1516722861" + "</mch_id>"
                    + "<nonce_str>" + nonceStr + "</nonce_str>"
                    + "<sign>" + mysign + "</sign>"
                    + "</xml>";
        System.out.println(xml);
        // 调用统一下单接口，并接受返回的结果
        String result = PayUtils.httpRequest("https://api.mch.weixin.qq.com/pay/downloadbill", "POST", xml);

        System.out.println(result);



    }
}
